﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

namespace cms.libs
{
    [Serializable]
    public class Advert
    {
        #region AdvertType enum

        public enum AdvertType : byte
        {
            All = 0,
            Image = 1,
            Flash = 2,
            Html = 3
        }

        #endregion AdvertType enum

        public int Id { get; set; }

        public string Name { get; set; }

        public string Description { get; set; }

        public int Type { get; set; }

        public string State { get; set; }

        public string LinkUrl { get; set; }

        public int PosID { get; set; }

        public DateTime StartTime { get; set; }

        public DateTime EndTime { get; set; }

        public DateTime PostTime { get; set; }

        public int UserID { get; set; }

        public int ClickCount { get; set; }

        public int Status { get; set; }

//        public int Insert()
//        {
//            DBHelper db = null;
//            db = new DBHelper(Config.SQLConn);
//            var oCommand = new SqlCommand("sp_Advert_Insert");
//            oCommand.CommandType = CommandType.StoredProcedure;
//            var output = new SqlParameter("@Id", SqlDbType.Int);
//            output.Direction = ParameterDirection.Output;
//            db.ExecuteNonQuery(oCommand,
//                               new SqlParameter("@Name", Name),
//                               new SqlParameter("@Description", Description),
//                               new SqlParameter("@Type", Type),
//                               new SqlParameter("@State", State),
//                               new SqlParameter("@LinkUrl", LinkUrl),
//                               new SqlParameter("@PosID", PosID),
//                               new SqlParameter("@StartTime", StartTime),
//                               new SqlParameter("@EndTime", EndTime),
//                               new SqlParameter("@UserID", UserID),
//                               new SqlParameter("@Status", Status),
//                               output
//                );
//            return (int) output.Value;
//        }
//
//        public void Update()
//        {
//            DBHelper db = null;
//            db = new DBHelper(Config.SQLConn);
//            var oCommand = new SqlCommand("sp_Advert_Update");
//            oCommand.CommandType = CommandType.StoredProcedure;
//            db.ExecuteNonQuery(oCommand,
//                               new SqlParameter("@Id", Id),
//                               new SqlParameter("@Name", Name),
//                               new SqlParameter("@Description", Description),
//                               new SqlParameter("@State", State),
//                               new SqlParameter("@LinkUrl", LinkUrl),
//                               new SqlParameter("@PosID", PosID),
//                               new SqlParameter("@StartTime", StartTime),
//                               new SqlParameter("@EndTime", EndTime),
//                               new SqlParameter("@UserID", UserID)
//                );
//        }
//
//        public void Delete(int Id)
//        {
//            DBHelper db = null;
//            db = new DBHelper(Config.SQLConn);
//            var oCommand = new SqlCommand("sp_Advert_Delete");
//            oCommand.CommandType = CommandType.StoredProcedure;
//            db.ExecuteNonQuery(oCommand,
//                               new SqlParameter("@Id", Id)
//                );
//            new Advert2Cate {AdvID = Id}.DeleteByAdvID();
//        }
//
//        public Advert GetInfo(int Id)
//        {
//            var l_Advert_left = new Advert();
//            string key = "Advert_GetInfo_ArrId_" + Id;
//            if (CacheUtil.GetCache(key) != null)
//            {
//                l_Advert_left = (Advert) CacheUtil.GetCache(key);
//            }
//            else
//            {
//                DBHelper db = null;
//                db = new DBHelper(Config.SQLConn);
//                var oCommand = new SqlCommand("sp_Advert_Get");
//                oCommand.CommandType = CommandType.StoredProcedure;
//                l_Advert_left = db.GetList<Advert>(oCommand,
//                                                   new SqlParameter("@Id", Id)
//                    )[0];
//                CacheUtil.SetCacheWithTime(key, l_Advert_left, 10);
//            }
//            return l_Advert_left;
//        }
//
//        public List<Advert> GetPaged(AdvertType Type, string Keyword, int CateID, int PosID, DateTime FromDate,
//                                     DateTime ToDate, int CurrPage, int RecordPerPage, out int TotalRecord)
//        {
//            DBHelper db = null;
//            db = new DBHelper(Config.SQLConn);
//            var oCommand = new SqlCommand("sp_Advert_GetPaged");
//            oCommand.CommandType = CommandType.StoredProcedure;
//            var output = new SqlParameter("@TotalRecord", SqlDbType.Int);
//            output.Direction = ParameterDirection.Output;
//            List<Advert> lRet = db.GetList<Advert>(oCommand,
//                                                   new SqlParameter("@Type", (int) Type),
//                                                   new SqlParameter("@Keyword", Keyword),
//                                                   new SqlParameter("@CateID", CateID),
//                                                   new SqlParameter("@PosID", PosID),
//                                                   new SqlParameter("@FromDate", FromDate),
//                                                   new SqlParameter("@ToDate", ToDate),
//                                                   new SqlParameter("@CurrPage", CurrPage),
//                                                   new SqlParameter("@RecordPerPage", RecordPerPage),
//                                                   output
//                );
//            TotalRecord = (int) output.Value;
//            return lRet;
//        }
    }
}